import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dikede',
    children: [{
      path: 'dikede',
      name: 'dikede',
      component: () => import('@/views/dikede/index'),
      meta: { title: '帝可得', icon: 'dashboard' }
    }]
  },

  {
    path: '/workOrders',
    component: Layout,
    redirect: '/workOrders',
    name: 'workOrders',
    meta: { title: '工单管理', icon: 'form' },
    children: [
      {
        path: 'operationOrder',
        component: () => import('@/views/workOrders/operationOrder.vue'),
        name: 'operationOrder',
        meta: { title: '运营工单' }
      },
      {
        path: 'omOrders',
        component: () => import('@/views/workOrders/omOrders.vue'),
        name: 'omOrders',
        meta: { title: '运维工单' }
      }

    ]
  },
  {
    path: '/point',
    component: Layout,
    redirect: '/point',
    name: 'Point',
    meta: { title: '点位管理', icon: 'form' },
    children: [
      {
        path: 'region',
        component: () => import('@/views/Point/region.vue'),
        name: 'region',
        meta: { title: '区域管理' }
      },
      {
        path: 'sonPoint',
        component: () => import('@/views/Point/sonPoint.vue'),
        name: 'sonPoint',
        meta: { title: '点位管理' }
      },
      {
        path: 'Partners',
        component: () => import('@/views/Point/Partners.vue'),
        name: 'Partners',
        meta: { title: '合作商管理' }
      }

    ]
  },
  {
    path: '/Equipment',
    component: Layout,
    redirect: '/Equipment',
    name: 'Equipment',
    meta: { title: '设备管理', icon: 'form' },
    children: [
      {
        path: 'sonEquipment',
        component: () => import('@/views/Equipment/sonEquipment.vue'),
        name: 'sonEquipment',
        meta: { title: '设备管理' }
      },
      {
        path: 'equipmentStatus',
        component: () => import('@/views/Equipment/equipmentStatus.vue'),
        name: 'equipmentStatus',
        meta: { title: '设备状态' }
      },
      {
        path: 'equipmentType',
        component: () => import('@/views/Equipment/equipmentType.vue'),
        name: 'equipmentType',
        meta: { title: '设备类型管理' }
      }

    ]
  },
  {
    path: '/renyuan',
    component: Layout,
    redirect: '/renyuan',
    name: 'renyuan',
    meta: { title: '人员管理', icon: 'form' },
    children: [
      {
        path: 'son1',
        component: () => import('@/views/renyuan/son1.vue'),
        name: 'son1',
        meta: { title: '人员列表' }
      },
      {
        path: 'son2',
        component: () => import('@/views/renyuan/son2.vue'),
        name: 'son2',
        meta: { title: '人效统计' }
      },
      {
        path: 'son3',
        component: () => import('@/views/renyuan/son3.vue'),
        name: 'son3',
        meta: { title: '工作量列表' }
      }

    ]
  },
  {
    path: '/shopping',
    component: Layout,
    redirect: '/shopping',
    name: 'shopping',
    meta: { title: '商品管理', icon: 'form' },
    children: [
      {
        path: 'son1',
        component: () => import('@/views/shopping/son1.vue'),
        name: 'son1',
        meta: { title: '商品类型' }
      },
      {
        path: 'son2',
        component: () => import('@/views/shopping/son2.vue'),
        name: 'son2',
        meta: { title: '商品管理' }
      }
    ]
  },
  {
    path: '/celue',
    component: Layout,
    redirect: '/celue',
    children: [
      {
        path: 'index',
        name: 'celue',
        component: () => import('@/views/celue/index'),
        meta: { title: '策略', icon: 'form' }
      }
    ]
  },
  {
    path: '/dingdan',
    component: Layout,
    redirect: '/dingdan',
    children: [
      {
        path: 'index',
        name: 'dingdan',
        component: () => import('@/views/dingdan/index'),
        meta: { title: '订单管理', icon: 'form' }
      }
    ]
  },
  {
    path: '/duizhang',
    component: Layout,
    redirect: '/duizhang',
    children: [
      {
        path: 'index',
        name: 'duizhang',
        component: () => import('@/views/duizhang/index'),
        meta: { title: '对账统计', icon: 'form' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
